﻿-- =============================================
-- Author:		<Author,徐福龙>
-- Create date: <Create Date,2012 03 06>
-- Description:	<Description,员工工资临时增减 添加高级搜索>
-- =============================================

CREATE PROCEDURE [dbo].[proc_Employee_WageTempZj_GetList]
	(
		@StartIndex int,
		@EndIndex int,
		@CompanyId nvarchar(500),
		@EName nvarchar(50)
	)
AS
	Begin
				

--	将公司ID串 插入临时表中
	declare @Companyid_T table(id int identity(1,1),cid int)
	declare @CompanyID_S varchar(500)
--	给公司串 赋值
	set @CompanyID_S=@CompanyId+','
	Declare @i int
	Set @i=0
	while(@i<len(@CompanyID_S))
	begin 
	Insert Into @Companyid_T(cid) Values(substring(@CompanyID_S,@i,charindex(',',@CompanyID_S,@i)-@i))
	Set @i=charindex(',',@CompanyID_S,@i)+1
	end
	
--	select * from Company  where id in (select cid from @Companyid_T)
				
		;WITH list As(Select ROW_NUMBER() OVER (ORDER BY Employee_WageTempZj.Id DESC)AS Row, 
			Id
			,CompanyId
			,CompanyName
			,UserName
			,EName
			,CategoryId
			,CategoryName
			,Price
			,Memo
			,FsDate
			,CreateName
			,CreateDate
		From
			Employee_WageTempZj
		Where 
			(@CompanyId='0' or CompanyId in (select C.cid from @Companyid_T C))
			 and EName Like '%'+@EName+'%'			    
		)
		Select *,(select count(0) from list) AS Count_Sum	 From list Where Row between @StartIndex and @EndIndex 						    
	End
	RETURN
